Name "N-CAT"
Caption "N-CAT Installer"
OutFile "ncat-1.0.0.x_win32_setup.exe"
CRCCheck force
;BGGradient 000000 000080 FFFFFF
InstallColors F0F0F0 000020
InstallDir "C:\N-CAT"
InstallDirRegKey HKLM "Software\NCAT10015" "Install_Dir"
LicenseText "License"
LicenseData "README.txt"

Page license
Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

Section "N-CAT (required)"
SectionIn RO
;SetShellVarContext all
SetOutPath $INSTDIR
File ncat.exe
File QtCore4.dll
File QtGui4.dll
File QtOpenGL4.dll
File QtSql4.dll 
File QtSvg4.dll 
File QtXml4.dll 
File fbclient.dll
File firebird.msg
File firebird.conf
File ib_util.dll
File mingwm10.dll
File msvcp60.dll
File gfix.exe
File gsplit.exe
File validate.bat
File mend.bat
File flamerobin-0.8.6-win32.7z
File splash_image.png
File isql.exe
File isql_emb.bat
File LICENSE.txt
File "README.txt"
File /r sqldrivers
File /r imageformats
File /r codecs
File /r bin
File /r iconengines
File /r intl
File /r ncat-manual
File /r schema

; Write the installation path into the registry
WriteRegStr HKLM "SOFTWARE\NCAT10015" "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NCAT10015" "DisplayName" "N-CAT (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NCAT10015" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NCAT10015" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NCAT10015" "NoRepair" 1
WriteUninstaller "uninstall.exe"

IfFileExists "$INSTDIR\COLL0.FDB" OverwrQuest RealOverwrite

OverwrQuest:
MessageBox MB_YESNO|MB_ICONQUESTION "Overwrite embedded database $INSTDIR\COLL0.FDB?" IDYES Overwrite IDNO NoOverwrite

Overwrite:
MessageBox MB_YESNO|MB_ICONQUESTION "Sure? Overwrite $INSTDIR\COLL0.FDB?" IDNO NoOverwrite IDYES RealOverwrite 

RealOverwrite:
File COLL0.FDB

NoOverwrite:
Nop

SectionEnd

Section "Start Menu Shortcuts"
;SetShellVarContext all
CreateDirectory "$SMPROGRAMS\N-CAT"
CreateDirectory "$SMPROGRAMS\N-CAT\Build-in DB Advanced"
;CreateShortCut "$SMPROGRAMS\N-CAT\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\N-CAT\N-CAT.lnk" "$INSTDIR\ncat.exe" "" "$INSTDIR\ncat.exe" 0
CreateShortCut "$SMPROGRAMS\N-CAT\Build-in DB Advanced\Validate DB.lnk" "$INSTDIR\validate.bat" "" "$INSTDIR\validate.bat" 0
CreateShortCut "$SMPROGRAMS\N-CAT\Build-in DB Advanced\Prepare corrupted DB for backup.lnk" "$INSTDIR\mend.bat" "" "$INSTDIR\mend.bat" 0
CreateShortCut "$SMPROGRAMS\N-CAT\Build-in DB Advanced\SQL.lnk" "$INSTDIR\isql_emb.bat" "" "$INSTDIR\isql_emb.bat" 0
SectionEnd

Section "Desktop Shortcut"
;SetShellVarContext all
CreateShortCut "$DESKTOP\N-CAT.lnk" "$INSTDIR\ncat.exe" "" "$INSTDIR\ncat.exe" 0
SectionEnd

Section "Uninstall"
;SetShellVarContext all
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NCAT10015"
DeleteRegKey HKLM "SOFTWARE\NCAT10015"
; Remove files and uninstaller
Delete "$INSTDIR\ncat.exe"
Delete "$INSTDIR\QtCore4.dll"
Delete "$INSTDIR\QtGui4.dll"
Delete "$INSTDIR\QtOpenGL4.dll"
Delete "$INSTDIR\QtSql4.dll" 
Delete "$INSTDIR\QtSvg4.dll" 
Delete "$INSTDIR\QtXml4.dll" 
Delete "$INSTDIR\fbclient.dll"
Delete "$INSTDIR\firebird.msg"
Delete "$INSTDIR\firebird.conf"
Delete "$INSTDIR\ib_util.dll"
Delete "$INSTDIR\mingwm10.dll"
Delete "$INSTDIR\msvcp60.dll"
Delete "$INSTDIR\validate.bat"
Delete "$INSTDIR\mend.bat"
Delete "$INSTDIR\sqldrivers\*.*"
Delete "$INSTDIR\imageformats\*.*"
Delete "$INSTDIR\codecs\*.*"
Delete "$INSTDIR\bin\*.*"
Delete "$INSTDIR\iconengines\*.*"
Delete "$INSTDIR\intl\*.*"
Delete "$INSTDIR\isql.exe"
Delete "$INSTDIR\gsplit.exe"
Delete "$INSTDIR\gbak.exe"
Delete "$INSTDIR\gfix.exe"
Delete "$INSTDIR\gstat.exe"
Delete "$INSTDIR\isql.exe"
Delete "$INSTDIR\isql_emb.bat"
Delete "$INSTDIR\splash_image.png"
Delete "$INSTDIR\LICENSE.txt"
Delete "$INSTDIR\README.txt"
RMDir  "$INSTDIR\codecs"
RMDir  "$INSTDIR\bin"
RMDir  "$INSTDIR\accessible"
RMDir  "$INSTDIR\iconengines"
RMDir  "$INSTDIR\sqldrivers"
RMDir  "$INSTDIR\imageformats"
RMDir  "$INSTDIR\intl"
Delete "$DESKTOP\N-CAT.lnk"
Delete "$SMPROGRAMS\N-CAT\Build-in DB Advanced\*.*"
RMDir  "$SMPROGRAMS\N-CAT\Build-in DB Advanced"
Delete "$SMPROGRAMS\N-CAT\*.*"
RMDir  "$SMPROGRAMS\N-CAT"
Delete "$APPDATA\N-CAT\*.*"
RMDir  "$APPDATA\N-CAT"
Delete "$INSTDIR\flamerobin-0.8.6-win32.7z"
Delete "$INSTDIR\firebird.log"
Delete "$INSTDIR\flamerobin_unicode.exe"
Delete "$INSTDIR\msvcp71.dll"
Delete "$INSTDIR\msvcr71.dll"
Delete "$INSTDIR\html-templates\*.*"
RMDir  "$INSTDIR\html-templates"
Delete "$INSTDIR\docs\*.*"
RMDir  "$INSTDIR\docs"
Delete "$INSTDIR\conf-defs\*.*"
RMDir  "$INSTDIR\conf-defs"
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\ncat-manual\*.*"
RMDir "$INSTDIR\ncat-manual"
Delete "$INSTDIR\schema\*.*"
RMDir "$INSTDIR\schema"
MessageBox MB_YESNO|MB_ICONQUESTION "Remove embedded database and data?" IDNO NoDataRemove IDYES RemoveData 

RemoveData:
MessageBox MB_YESNO|MB_ICONQUESTION "Sure? Remove database and data?" IDNO NoDataRemove IDYES RealRemove

RealRemove:
Delete "$INSTDIR\COLL0.FDB"

NoDataRemove:
Nop

SectionEnd
